<?php

namespace App\Http\Requests\Permission;

use Illuminate\Foundation\Http\FormRequest;

class UpdatePermissionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true; // 在实际应用中，你可能需要根据用户权限来判断
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => 'sometimes|string|max:255',
            'slug' => 'sometimes|string|max:255|unique:permissions,slug,' . $this->permission->id,
            'description' => 'nullable|string',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息。
     */
    public function messages(): array
    {
        return [
            'slug.unique' => '权限标识已存在',
        ];
    }
}
